<?
/**
*鼓浪屿轮渡
*2015-03-17 by pzp
*九天不记录票付通的订单号
**/
class Ferry_gly{
	private $USER ='piaofutong'; //账号
	private $PWD ='piaofutong'; //密码
	// private $reURL = 'http://jtsvn.eicp.net:3322/today/fx/';//提交地址
	private $reURL = 'http://120.24.86.172:8081/today/fx/';//提交地址
	
	//查询航线信息
	public function getFlightLine(){ 
		$action = 'getFlightLine.do';
		$str_array = array();
		$response = $this->Ferry_POST($action,$str_array);
		return $response;
	}
	
	//查询余票接口
	public function getDailyFlight($flightLineid,$date){
		$action = 'getDailyFlight.do';
		$str_array = array(
					'fightDate' =>$date,
					'flightLineId'=>$flightLineid
		);
		// print_r($str_array);exit;
		$response = $this->Ferry_POST($action,$str_array);
		return $response;
	}
	
	//推送订单接口
	public function saveSaleOrder($submit_array){
		$action = 'saveSaleOrder.do';
		$amount = $submit_array['Tnum'] * $submit_array['gprice'];
		$content =<<<XML
<saleOrder>
	<sno></sno>
	<ebusinessOrder>{$submit_array['Ordern']}</ebusinessOrder>
	<dailyFlightGid>{$submit_array['dailyFlightGid']}</dailyFlightGid>
	<seat>{$submit_array['Tnum']}</seat>
	<amount>{$amount}</amount>
	<list>
		<item>
			<ticket>
				<id>{$submit_array['ticketid']}</id>
				<name>全价票35</name>
				<price>{$submit_array['gprice']}</price>
			</ticket>
			<person>
				<identityType>二代身份证</identityType> 
				<name>{$submit_array['ordername']}</name>
				<identityNO>{$submit_array['IDcar']}</identityNO>
				<phoneNumber>{$submit_array['tel']}</phoneNumber>
				<children>0</children>
			</person>
		</item>
	</list>
</saleOrder>
XML;
		$str_array = array(
					'content'=>$content
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;
	}
	
	// 支付成功接口
	public function payForSaleOrder($sno){
		$action = 'payForSaleOrder.do'; 
		$str_array = array(
					'sno'=>$sno, //1503181426387077
					'payment'=>'在线支付'
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;	
	}
	
	//取消回调(支付)接口
	public function saveCancel($UUremotenum){
		$action = 'saveCancel.do';
		$str_array = array(
					'sno'=>$UUremotenum,
		);
		$response = $this->Ferry_POST($action,$str_array);
				logfile($UUremotenum."->".$response);
		return $response;	
	}
	
	//查询订单接口
	public function findSaleOrder(){
		$action = 'findSaleOrder.do';
		$str_array = array(
					'sno'=>'1507031058024453',
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;		
	}	
	
	//退票接口
	public function saveReturn($UUremotenum){
		$action = 'saveReturn.do';
		$str_array = array(
					'sno'=>$UUremotenum,
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;		
	}
	
	//提交数据
	public function Ferry_POST($action,$str_array){
		$USER = $this->USER;
		$PWD = $this->PWD;
		$post_data= http_build_query($str_array);
		$request_URL=$this->reURL.$action;
		// echo $request_URL;exit;
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_POST, 1); 
		curl_setopt($ch, CURLOPT_HEADER, 0); 
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
		curl_setopt($ch, CURLOPT_URL,$request_URL); 	
		curl_setopt($ch, CURLOPT_USERPWD,"{$this->USER}:{$this->PWD}"); 
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		$result = curl_exec($ch);
		if (!$result) {  
			return curl_error($ch);  
		}else {  
			return $result;  
		}     	
	}
	
}
$gly_client = new Ferry_gly(); 
$getFlightLine = $gly_client->getFlightLine(); print_r('查询航线'.$getFlightLine);//查询航线信息
// $getDailyFlight = $gly_client->getDailyFlight("167B6542C83A4F94871B54DADCE049E9","20150925"); 
// $getDailyFlight  = simplexml_load_string($getDailyFlight);
// print_r($getDailyFlight);
//查询余票 
// $saveSaleOrder = $gly_client->saveSaleOrder(); print_R('提交订单'.$saveSaleOrder); //推送订单
// $payForSaleOrder = $gly_client->payForSaleOrder();print_r('支付订单'.$payForSaleOrder); //支付成功接口
// $saveCancel = $gly_client->saveCancel();print_r('取消支付'.$saveCancel);
// $findSaleOrder = $gly_client->findSaleOrder();print_r('查询订单'.$findSaleOrder);
// $saveReturn = $gly_client->saveReturn();print_r('取消订单'.$saveReturn);
?>